package jk.spider.util.seed;

import jk.spider.core.SpiderController;
import jk.spider.core.storage.Storage;
import jk.spider.util.ParserUtil;
import jk.spider.util.config.PropertySet;

public abstract class Seed {
	protected SpiderController controller;
	protected PropertySet props;
	protected Storage storage;
	protected String baseFilePath;
	
	public Seed(SpiderController controller, PropertySet props ) {
		this.controller = controller;
		this.props = props;
		this.storage = controller.getStorage();
		
		String sql = ParserUtil.getFileContent(controller.getProjectPath() + "/config/sql/JK_Spider-2.0.sql");

		dropAll();
		this.createTable(sql.replaceAll("[\n\r]", " "));
		
		baseFilePath = controller.getProjectPath() + "/config/";
	}
	
	public void dropAll() {
		StringBuffer sql = new StringBuffer();
		sql.append("drop index Resource_Url_Index;");
		sql.append("drop index Sinfo_Url_Index;");
		sql.append("drop table Spider_resource_info;");
		sql.append("drop table Spider_resource_imgInfo;");
		sql.append("drop table Spider_folder;");
		sql.append("drop table Spider_sinfo;");
		sql.append("drop table Spider_check;");
		sql.append("drop table Sinfo_url;");
		sql.append("drop table Spider_info;");
		sql.append("drop table Spider_resource;");
		sql.append("drop table Spider_proxy;");
		
		storage.getDAOHelp().execSql(sql.toString());
	}
	
	public void createTable(String sql) {
		storage.getDAOHelp().execSql(sql);
	}
	
	public abstract void dealSeed();
	
	private static final String tableSql = "";
}
